package game.VO
{
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * @author Kirill Pletnev
	 */
	public class MapObjectVO
	{
		public var objectId:String;
		public var columnPosition:int;
		public var rowPosition:int;
		public var numColumn:int;
		public var numRow:int;
		public var direction:int;
		public var creationTimestamp:Number;
		public var level:int;
		public var physicalFlags:Vector.<int>;
		public var canMove:Boolean;
		public var textureURL:String;
		
		public function MapObjectVO()
		{
		}
		
		public function clone():MapObjectVO
		{
			var vo:MapObjectVO = new MapObjectVO();
			
			vo.objectId = this.objectId;
			vo.columnPosition = this.columnPosition;
			vo.rowPosition = this.rowPosition;
			vo.numColumn = this.numColumn;
			vo.numRow = this.numRow;
			vo.direction = this.direction;
			vo.creationTimestamp = this.creationTimestamp;
			vo.level = this.level;
			vo.physicalFlags = this.physicalFlags;
			vo.canMove = this.canMove;
			vo.textureURL = this.textureURL
			
			return vo;
		}
		
		// SERIALIZATION ========================================================================
		public function serialize(data:ByteArray):void
		{
			data.writeUTF(objectId);
			data.writeShort(columnPosition);
			data.writeShort(rowPosition);
			data.writeShort(numColumn);
			data.writeShort(numRow);
			data.writeShort(direction);
			data.writeDouble(creationTimestamp);
			data.writeShort(level);
			
			data.writeInt(physicalFlags.length);
			for each (var physicalFlag:int in physicalFlags)
			{
				data.writeInt(physicalFlag);
			}
			
			data.writeBoolean(canMove);
			data.writeUTF(textureURL);
		}
		
		public static function deserialize(data:ByteArray):MapObjectVO
		{
			var vo:MapObjectVO = new MapObjectVO();
			
			vo.objectId = data.readUTF();
			vo.columnPosition = data.readShort();
			vo.rowPosition = data.readShort();
			vo.numColumn = data.readShort();
			vo.numRow = data.readShort();
			vo.direction = data.readShort();
			vo.creationTimestamp = data.readDouble();
			vo.level = data.readShort();
			
			var length:int = data.readInt();
			
			vo.physicalFlags = new Vector.<int>();
			for (var i:int = 0; i < length; i++)
			{
				var physicalFlag:int = data.readInt();
				vo.physicalFlags.push(physicalFlag);
			}
			
			vo.canMove = data.readBoolean();
			vo.textureURL = data.readUTF();
			
			return vo;
		}
		
		public function toString():String
		{
			return "[MapObjectVO objectId=" + objectId + " columnPosition=" + columnPosition + " rowPosition=" + rowPosition + " numColumn=" + numColumn + " numRow=" + numRow + " direction=" + direction + " creationTimestamp=" + creationTimestamp + " level=" + level + " physicalFlags=" + physicalFlags + " canMove=" + canMove + " textureURL=" + textureURL + "]";
		}
	}

}